//
//  RequestManager.swift
//  jingxin
//
//  Created by Yuki on 2020/8/6.
//  Copyright © 2020 Zl. All rights reserved.
//

import UIKit
import Alamofire//网络请求
typealias RequestSuccess = (_ responseData:AnyObject)->Void;//请求成功

class RequestManager: NSObject {
    
    /**  Post请求  **/
    public class func postRequestWith(cmd:String, param:NSDictionary,success:@escaping RequestSuccess) {
        
        let cmdStr = RequestConfig.RequestURL() + cmd;//请求地址+接口
        let tokenStr :String = "Bearer " + token(); //获取 token
        
        let header :HTTPHeaders = [
            "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",
            "Authorization": tokenStr
        ];
        
        
        Alamofire.request(cmdStr, method: .post, parameters: param as? Parameters, encoding: URLEncoding.queryString, headers: header).responseJSON { (responseData) in
            if responseData.result.isSuccess{
                print(responseData);
                success(responseData.result.value as AnyObject);
            }else{
                print("请求出现错误");
            }
        };
    }

    
    /// 获取token
    /// - Returns: String token值
    private class func token() -> String {
        return "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMTg5NDg4ODg0OTI3ODMyMDY1Iiwicm9sZXMiOiJ1c2VyIiwiaWF0IjoxNTk2NDMyNjY1LCJleHAiOjE1OTkwMjQ2NjV9._75ZMmFW7jy_Keo83oIYPTCBC73fvwNhHJkhDbfwFzA"
    }
}
